package cn.darkfire.web.Utils;

import com.mchange.v2.c3p0.ComboPooledDataSource;
import org.junit.Test;

import javax.sql.DataSource;
import java.sql.Connection;

public class C3P0Util {
    private static DataSource ds = null;

    static {
        ds = new ComboPooledDataSource();


    }
    public static DataSource getDs(){
        return ds;
    }
    public static Connection getConnection(){
        try{
            return ds.getConnection();
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }

    }

    //单元测试
    @Test
    public void test(){
        for(int i = 0;i<9;i++){
            Connection con = getConnection();
            System.out.println(i+":"+con);
            if(i==5){
                try{
                    con.close();
                }catch (Exception e){
                    e.printStackTrace();
                }
            }
        }
    }
}
